﻿DROP TRIGGER IF EXISTS  `pk_group_pro_gallery_log`;
CREATE   TRIGGER `pk_group_pro_gallery_log` AFTER INSERT ON `open_group_promotion_gallery`
  FOR EACH ROW BEGIN
DECLARE pkf varchar(50) DEFAULT "";
SELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="group_pro_gallery";
if pkf <> "group_pro_gallery" then
  INSERT INTO open_pk_log SET pk_from = 'group_pro_gallery', pk_id = NEW.img_id;
eLSE
   update open_pk_log SET pk_id = NEW.img_id WHERE pk_from = 'group_pro_gallery';
end if;
end;